package views.swing;

import java.awt.*;

import java.util.Hashtable;

public class PresentacionLayout implements LayoutManager{
	Hashtable<String, Component> tabla;
	
	public PresentacionLayout(){
		tabla=new Hashtable<String, Component>();
	}
	
	public void addLayoutComponent(String nombre, Component comp){
		tabla.put(nombre, comp);
	}
	
	public void removeLayoutComponent(Component comp){
	}
	
	public void layoutContainer(Container contenedor){
		Dimension d=contenedor.getSize();
		
		Component etiqueta=tabla.get("descripcion");
		etiqueta.setSize(new Dimension(d.width, etiqueta.getPreferredSize().height));
		etiqueta.setLocation(0, 0);
		
		Component opcion1=tabla.get("opcion 1");
		Dimension d1=opcion1.getPreferredSize();
		opcion1.setSize(d1);
		opcion1.setLocation(d.width-d1.width, d.height-d1.height);
	}
	
	public Dimension minimumLayoutSize(Container contenedor){
		Component c1=tabla.get("descripcion");
		Component c2=tabla.get("argumentos");
		Component c3=tabla.get("opcion 1");
		
		Dimension d1=null, d2=null, d3=null;
		
		if(c1!=null){
			d1=c1.getPreferredSize();
		}
		if(c2!=null){
			d2=c2.getPreferredSize();
		}
		if(c3!=null){
			d3=c3.getPreferredSize();
		}
		
		if(d2==null){
			return new Dimension(Math.max(d1.width, d3.width), d1.height+d3.height+20);
		}else{
			return new Dimension(Math.max(d2.width, d3.width), d1.height+d2.height+d3.height+20);
		}
	}
	
	public Dimension preferredLayoutSize(Container contenedor){
		return minimumLayoutSize(contenedor);
	}
}